<template>
    <!-- 
    <b-modal ref="my-modal" hide-footer title="Using Component Methods">
     <div class="d-block text-center">
       <h3>Hello From My Modal!</h3>
     </div>
     <b-button class="mt-3" variant="outline-danger" block @click="hideModal">Close Me</b-button>
     <b-button class="mt-2" variant="outline-warning" block @click="toggleModal">Toggle Me</b-button>
   </b-modal> 
    -->
    <!--
        body-class="modalStyle" 表示样式
        size="lg" 表示模态窗口大小 xl,lg,sm,full
        hide-footer 表示隐藏底部按钮
        hide-header 表示隐藏头部内容
        no-close-on-backdrop 表示鼠标点击背景不可关闭
        hide-header-close 表示隐藏头部关闭按钮
        centered 居中
        ok-title=“确定” 
        cancel-title=取消
        @ok="handleOk" 
        @cancel="handleCancel"
        scrollable 滚动条
        hide-backdrop 隐藏背景
        wrapClassName="ant-modal-cust-warp" 
        style="top:5%;height: 85%;overflow-y: hidden" 样式
    -->
    <b-modal ref="my-modal" size="xl" title="新建调度配置" scrollable no-close-on-backdrop>
        <div class="d-block text-center">
            <!--begin::div-->
            <div class="m-form m-form--fit m-form--label-align-right m-form--group-seperator-dashed">
                <div class="m-portlet__body">
                    <div class="form-group m-form__group row">
                        <label
                            class="col-lg-1 col-form-label">标&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;题</label>
                        <div class="col-lg-3">
                            <input class="form-control" type="text" maxlength="100" v-model="jobConfigForm.jobTitle" placeholder="请输入">
                        </div>
                    </div>
                    <div class="form-group m-form__group row">
                        <label class="col-md-1 col-form-label" jEhcLang="jobId">任务Id</label>
                        <div class="col-md-3">
                            <input class="form-control" type="text" maxlength="64" v-model="jobConfigForm.jobId" placeholder="请输入">
                        </div>
                        <label class="col-md-1 col-form-label" jEhcLang="jobName">任务名称</label>
                        <div class="col-md-3">
                            <input class="form-control" type="text" maxlength="64" v-model="jobConfigForm.jobName" placeholder="请输入">
                        </div>
                        <label class="col-md-1 col-form-label" jEhcLang="jobGroup">任务分组</label>
                        <div class="col-md-3">
                            <input class="form-control" type="text" maxlength="64" v-model="jobConfigForm.jobGroup" placeholder="请输入">
                        </div>
                    </div>
                    <div class="form-group m-form__group row">
                        <label class="col-md-1 col-form-label" jEhcLang="jobStatus">任务状态</label>
                        <div class="col-md-3">
                            <select class="form-control" v-model="jobConfigForm.jobStatus" style="width:150px;">
                                <option value="PAUSED">暂停</option>
                                <option value="NORMAL">启用</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group m-form__group row">
                        <label class="col-md-1 col-form-label" jEhcLang="cronExpression">运行时间表达式</label>
                        <div class="col-md-3">
                            <input class="form-control" type="text" maxlength="64" v-model="jobConfigForm.cronExpression" placeholder="请输入">
                        </div>
                    </div>
                    <div class="form-group m-form__group row">
                        <label class="col-md-1 col-form-label" jEhcLang="desc_">任务描述</label>
                        <div class="col-md-3">
                            <textarea class="form-control" maxlength="600" v-model="jobConfigForm.desc_" placeholder="请输入"></textarea>
                        </div>
                    </div>
                    <div class="form-group m-form__group row">
                        <label class="col-md-1 col-form-label" jEhcLang="clientId">客户端Id</label>
                        <div class="col-md-3">
                            <input class="form-control" type="text" maxlength="500" v-model="jobConfigForm.clientId" placeholder="请输入">
                        </div>
                        <label class="col-md-1 col-form-label" jEhcLang="clientGroupId">客户端组Id</label>
                        <div class="col-md-3">
                            <input class="form-control" type="text" maxlength="500" v-model="jobConfigForm.clientGroupId" placeholder="请输入">
                        </div>
                    </div>
                    <div class="form-group m-form__group row">
                        <label class="col-md-1 col-form-label" jEhcLang="jobHandler">注解事件</label>
                        <div class="col-md-3">
                            <input class="form-control" type="text" maxlength="500" v-model="jobConfigForm.jobHandler" placeholder="请输入">
                        </div>
                        <label class="col-md-1 col-form-label" jEhcLang="jobPara">参数</label>
                        <div class="col-md-3">
                            <input class="form-control" type="text" maxlength="500" v-model="jobConfigForm.jobPara" placeholder="请输入">
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <template slot="modal-footer">
            <!--自定义按钮-->
            <button type="button" class="btn btn-light-danger font-weight-bold mr-2" block @click="hideModal">
                <i class="icon-xl fa fa-times"></i>取消
            </button>
            <button type="button" class="btn btn-light-success font-weight-bold mr-2" @click="addJobConfig">
                <i class="icon-xl fas fa-save"></i> 保存
            </button>
        </template>
    </b-modal>
</template>
<script>
import apiUtil from "@/core/util/apiUtil.js";
import { handleNotify, handleAlert, handleConfirm, showWating, closeWating } from "@/core/util/jehcUtil.js";
export default {
    data() {
        return {
            jobConfigForm: {
                jobTitle: "",
                jobId:"",
                jobName:"",
                jobGroup:"",
                jobStatus:"",
                cronExpression:"",
                desc_: "",
                clientId: "",
                clientGroupId: "",
                jobHandler: "",
                jobPara: "",

            }
        }
    },
    components: {

    },
    watch: {
    },
    mounted() {

    },
    methods: {
        addJobConfig() {
            if (this.jobConfigForm.jobTitle === "") {
                handleAlert("请输入标题", "warning", 3)
                return;
            }
            if (this.jobConfigForm.jobId === "") {
                handleAlert("请输入jobId", "warning", 3)
                return;
            }
            if (this.jobConfigForm.jobName === "") {
                handleAlert("请输入任务名称", "warning", 3)
                return;
            }
            if (this.jobConfigForm.jobStatus === "") {
                handleAlert("请选择状态", "warning", 3)
                return;
            }
            // 保存前提示
            this.$confirm("确定保存?", "提示", { type: "warning", }).then(() => {
                apiUtil.post(process.env.VUE_APP_JOB_API + "/jobConfig/add", this.jobConfigForm).then(({ data }) => {
                    if (data.success) {
                        handleAlert("创建成功", "success", 3);
                        this.hideModal();//关闭窗体
                        this.$emit("change", data);//组件传值，即向父级模态框中传递值，采用change方式，目标刷新主列表使用
                    } else {
                        handleAlert("创建失败", "error", 3);
                    }
                });
            }).catch(() => { });//注意这里，这里是重点！！！;   
        },
        showModal() {
            this.restForm();
            this.$refs['my-modal'].show();
        },
        hideModal() {
            this.$refs['my-modal'].hide()
        },
        toggleModal() {
            // 当模态已隐藏时，我们传递要返回焦点的按钮的ID
            this.$refs['my-modal'].toggle('#toggle-btn')
        },
        restForm() {
            //重置
            Object.assign(this.$data.jobConfigForm, this.$options.data().jobConfigForm);
        },
    }
}
</script>